angular.module('starter.controllers')
.controller('OrderCtrl', function($scope, museumFac, $stateParams, $timeout, $ionicScrollDelegate, cfg, $location, $cookies, $interval) {
  	$scope.backhome = function(){
      $location.url('home');
    }

    $scope.gotoCenter = function(){
      museumFac.user.usertest(function(data){
        if(data.info == true){
          $location.url('center');
        }else{
          $scope.url = window.location.href;
              $cookies.put('lastPage', $scope.url);
          $location.url('login');
        }
      });
    }
  
    $scope.change_language = function(id){
      $scope.language = id;
      var expireDate = new Date();  
      expireDate.setDate(expireDate.getDate() + 30);                
      $cookies.put('language', id, {'expires': expireDate.toUTCString()});
      location.reload();
      if(id == 0){
        document.getElementById('title').innerHTML = '提示';
        document.getElementById('windowclosebutton').value = '确定';
      }else{
        document.getElementById('title').innerHTML = 'Hint';
        document.getElementById('windowclosebutton').value = 'Confirm';
      }

    }

    $scope.getLanguage = function(){
      $scope.language = $cookies.get('language');
      if($scope.language){
          $scope.language = $scope.language;
      }else{
          $scope.language = 0;
      }
      if($scope.language == 0){
        document.getElementById('title').innerHTML = '提示';
        document.getElementById('windowclosebutton').value = '确定';
      }else{
        document.getElementById('title').innerHTML = 'Hint';
        document.getElementById('windowclosebutton').value = 'Confirm';
      }
    }
    $scope.getLanguage();

    $scope.checkOpenid = function(){
      museumFac.user.usertest(function(data){
            $scope.is_login = data.info;
          },function(data){
            alert(data.data.info);
        });
    }
    $scope.checkOpenid();

    $scope.getOrder = function(){
      museumFac.user.orders(function(data){
          $scope.orders = data.info;
        },function(data){
          alert(data.data.info);
      });
    }
    $scope.getOrder();

    $scope.gotoPay = function(list){
      window.location.href = cfg.baseUrl + 'home/index/checkpay?orderId=' + list.id;
      // $location.url('checkpay/' + list.id);
    }

})